package ufc.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ufc.web.funcoes.Acao;


public class Controlador extends HttpServlet {
	private static final long serialVersionUID = 1L;
 
    public Controlador() {
        super();

    }
    private void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
    	
    	String parametro = request.getParameter("acao");
    	String cadastro = "ufc.web.funcoes." + parametro;
    	
    	try{
    		
    		Class<?> classe = Class.forName(cadastro);
    		Acao acao = (Acao) classe.newInstance();
    		acao.executa(request, response);
    		
    	}catch(Exception e){
    		e.printStackTrace();
    	}
   
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		execute(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		execute(request, response);
	}

}
